/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.kj.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.lang.DateUtils;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.JoinTable;
import com.jeesite.common.mybatis.annotation.JoinTable.Type;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.common.utils.excel.annotation.ExcelField;
import com.jeesite.common.utils.excel.annotation.ExcelField.Align;
import com.jeesite.common.utils.excel.annotation.ExcelFields;
import com.jeesite.common.utils.excel.fieldtype.CompanyType;
import com.jeesite.common.utils.excel.fieldtype.OfficeType;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
 * kj_activityEntity
 * @author hzy
 * @version 2021-07-06
 */
@Table(name="kj_activity", alias="a", columns={
		@Column(name="id", attrName="id", label="id", isPK=true),
		@Column(name="name", attrName="name", label="活动名", queryType=QueryType.LIKE),
		@Column(name="start_time", attrName="startTime", label="活动开始时间"),
		@Column(name="end_time", attrName="endTime", label="活动结束时间"),
		@Column(name="banner", attrName="banner", label="banner图"),
		@Column(name="img", attrName="img", label="封面图"),
		@Column(name="group_qrcode", attrName="groupQrcode", label="入群二维码"),
		@Column(name="content", attrName="content", label="活动介绍"),
		@Column(name="leader", attrName="leader", label="联系人",queryType=QueryType.LIKE),
		@Column(name="leader_phone", attrName="leaderPhone", label="联系人电话"),
		@Column(name="location", attrName="location", label="服务地点"),
		@Column(name="lat", attrName="lat", label="服务地点经度"),
		@Column(name="lon", attrName="lon", label="服务地点纬度"),
		@Column(name="activity_status", attrName="activityStatus", label="活动状态"),
		@Column(name="sign_start_time", attrName="signStartTime", label="报名开始时间"),
		@Column(name="sign_end_time", attrName="signEndTime", label="报名结束时间"),
		@Column(includeEntity=DataEntity.class),
		@Column(name="city_id", attrName="kjCity.id", label="所属城市"),
		@Column(name="city_name", attrName="kjCity.name", label="所属城市名"),
		@Column(name="is_hot", attrName="isHot", label="是否热门"),
		@Column(name="isort", attrName="isort", label="排序", isQuery = false),
		@Column(name = "activity_audit",attrName = "activityAudit",label="活动审核状态")
	}, joinTable={
		@JoinTable(type=Type.LEFT_JOIN, entity= KjCity.class, alias="c",
				on="c.id = a.city_id",
				columns={@Column(includeEntity=KjCity.class)})
}, orderBy=" if(activity_status = '4', 0, if(activity_status = '3', 1, if(activity_status = '2', 2, if(activity_status = '1', 4, 3)))) desc, start_time desc"
)
public class KjActivity extends DataEntity<KjActivity> {

	private static final long serialVersionUID = 1L;

	public static final String NOT_BEGIN = "0";//活动未开始报名
	public static final String SIGN_START_STATUS = "1";//已开始报名
	public static final String SIGN_END_STATUS = "2";//结束报名
	public static final String STARTING_STATUS = "3";//活动进行中
	public static final String END_STATUS = "4";//活动已结束
	public static final String STATUS_NORMAL = "0";//正常
	public static final String ISHOT = "1";//热门活动
	private String name;		// 活动名
	private Date startTime;		// 活动开始时间
	private Date endTime;		// 活动结束时间
	private String banner;		// banner图
	private String img;		// 封面图
	private String groupQrcode;		// 入群二维码
	private String content;		// 活动介绍
	private String leader;		// 联系人
	private String leaderPhone;		// 联系人电话
	private String location;		// 服务地点
	private String lat;		// 服务地点经度
	private String lon;		// 服务地点纬度
	private String activityStatus;		// 活动状态
	private Date signStartTime;		// 报名开始时间
	private Date signEndTime;		// 报名结束时间
	private KjCity kjCity;
	private String isHot;
	private String activityAudit; //活动审核状态
	private int isort;

	private List<KjActivityJob> activityJobList = ListUtils.newArrayList();

	public KjActivity() {
		this(null);
	}

	public KjActivity(String id){
		super(id);
	}


	@Valid
	@ExcelFields({
			@ExcelField(title="活动名", attrName="name", align=Align.CENTER, sort=10, fieldType= OfficeType.class),
			@ExcelField(title="所属城市", attrName="kjCity.name", align = Align.CENTER, sort=20, fieldType= CompanyType.class),
			@ExcelField(title="服务地点", attrName="location", align = Align.CENTER, sort=25, fieldType= CompanyType.class),
			@ExcelField(title="联系人", attrName="leader", align=Align.CENTER, sort=30),
			@ExcelField(title="联系电话", attrName="leaderPhone", align=Align.CENTER, sort=40),
			@ExcelField(title="报名开始时间", attrName="signStartTime", dataFormat="yyyy-MM-dd hh:mm", align=Align.LEFT, sort=50),
			@ExcelField(title="报名结束时间", attrName="signEndTime", dataFormat="yyyy-MM-dd hh:mm", align=Align.CENTER, sort=60),
			@ExcelField(title="活动开始时间", attrName="startTime", dataFormat="yyyy-MM-dd hh:mm",  align=Align.CENTER, sort=70),
			@ExcelField(title="活动结束时间", attrName="endTime", dataFormat="yyyy-MM-dd hh:mm", align=Align.CENTER, sort=80),
			@ExcelField(title="活动状态", attrName="activityStatus", dictType="activity_status", align=Align.CENTER, sort=90),
			@ExcelField(title="审核状态", attrName="activityAudit", dictType="activity_audit", align=Align.CENTER, sort=100),
			})

	@Length(min=0, max=1, message="活动审核状态长度不能超过 1 个字符")
	public String getActivityAudit() { return activityAudit; }


	public void setActivityAudit(String activityAudit) { this.activityAudit = activityAudit; }

	@NotBlank(message="活动名不能为空")
	@Length(min=0, max=255, message="活动名长度不能超过 255 个字符")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}



	// 大于等于 >=
	public Date getCreateDate_gte(){
		return sqlMap.getWhere().getValue("start_time", QueryType.GTE);
	}

	public void setCreateDate_gte(Date createDate){
		createDate = DateUtils.getOfDayFirst(createDate); // 将日期的时间改为0点0分0秒
		sqlMap.getWhere().and("start_time", QueryType.GTE, createDate);
	}

	// 小于等于 <=
	public Date getCreateDate_lte(){
		return sqlMap.getWhere().getValue("end_time", QueryType.LTE);
	}

	public void setCreateDate_lte(Date createDate){
		createDate = DateUtils.getOfDayLast(createDate); // 将日期的时间改为23点59分59秒
		sqlMap.getWhere().and("end_time", QueryType.LTE, createDate);
	}

	public String getBanner() {
		return banner;
	}

	public void setBanner(String banner) {
		this.banner = banner;
	}

	@Length(min=0, max=255, message="封面图长度不能超过 255 个字符")
	public String getImg() {
		return img;
	}

	public void setImg(String img) {
		this.img = img;
	}

	@Length(min=0, max=255, message="入群二维码长度不能超过 255 个字符")
	public String getGroupQrcode() {
		return groupQrcode;
	}

	public void setGroupQrcode(String groupQrcode) {
		this.groupQrcode = groupQrcode;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Length(min=0, max=255, message="联系人长度不能超过 255 个字符")
	public String getLeader() {
		return leader;
	}

	public void setLeader(String leader) {
		this.leader = leader;
	}

	@Length(min=0, max=255, message="联系人电话长度不能超过 255 个字符")
	public String getLeaderPhone() {
		return leaderPhone;
	}

	public void setLeaderPhone(String leaderPhone) {
		this.leaderPhone = leaderPhone;
	}

	@Length(min=0, max=9999, message="服务地点长度不能超过 9999 个字符")
	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	@Length(min=0, max=255, message="服务地点经度长度不能超过 255 个字符")
	public String getLat() {
		return lat;
	}

	public void setLat(String lat) {
		this.lat = lat;
	}

	@Length(min=0, max=255, message="服务地点纬度长度不能超过 255 个字符")
	public String getLon() {
		return lon;
	}

	public void setLon(String lon) {
		this.lon = lon;
	}

	@Length(min=0, max=1, message="活动状态长度不能超过 1 个字符")
	public String getActivityStatus() {
		return activityStatus;
	}

	public void setActivityStatus(String activityStatus) {
		this.activityStatus = activityStatus;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
	public Date getSignStartTime() {
		return signStartTime;
	}

	public void setSignStartTime(Date signStartTime) {
		this.signStartTime = signStartTime;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
	public Date getSignEndTime() {
		return signEndTime;
	}

	public void setSignEndTime(Date signEndTime) {
		this.signEndTime = signEndTime;
	}

	@NotNull(message="所属城市不能为空")
	public KjCity getKjCity() {
		if (kjCity == null){
			kjCity = new KjCity();
		}
		return kjCity;
	}

	public void setKjCity(KjCity kjCity) {
		this.kjCity = kjCity;
	}


	public void setActivityStatusNotIn(String[] statuses){
		getSqlMap().getWhere().and("activity_status", QueryType.NOT_IN, statuses);
	}

	public String getActivityStatusNotIn(){
		return getSqlMap().getWhere().getValue("activity_status", QueryType.NOT_IN);
	}

	public void setStartTime_lte(Date date){
		getSqlMap().getWhere().and("start_time", QueryType.LTE, date);
	}
	public Date getStartTime_lte(){
		return getSqlMap().getWhere().getValue("start_time", QueryType.LTE);
	}

	public void setStartTime_gte(Date date){
		getSqlMap().getWhere().and("start_time", QueryType.GTE, date);
	}

	public Date getStartTime_gte(){
		return getSqlMap().getWhere().getValue("start_time", QueryType.GTE);
	}

	public void setEndTime_lte(Date date){
		getSqlMap().getWhere().and("end_time", QueryType.LTE, date);
	}

	public Date getEndTime_lte(){
		return getSqlMap().getWhere().getValue("end_time", QueryType.LTE);
	}

	public void setEndTime_gte(Date date){
		getSqlMap().getWhere().and("end_time", QueryType.GTE, date);
	}

	public Date getEndTime_gte(){
		return getSqlMap().getWhere().getValue("end_time", QueryType.GTE);
	}

	public void setStartSignTime_lte(Date date){
		getSqlMap().getWhere().and("sign_start_time", QueryType.LTE, date);
	}
	public Date getStartSignTime_lte(){
		return getSqlMap().getWhere().getValue("sign_start_time", QueryType.LTE);
	}

	public void setStartSignTime_gte(Date date){
		getSqlMap().getWhere().and("sign_start_time", QueryType.GTE, date);
	}

	public Date getStartSignTime_gte(){
		return getSqlMap().getWhere().getValue("sign_start_time", QueryType.GTE);
	}

	public void setEndSignTime_lte(Date date){
		getSqlMap().getWhere().and("sign_end_time", QueryType.LTE, date);
	}

	public Date getEndSignTime_lte(){
		return getSqlMap().getWhere().getValue("sign_end_time", QueryType.LTE);
	}

	public void setEndSignTime_gte(Date date){
		getSqlMap().getWhere().and("sign_end_time", QueryType.GTE, date);
	}

	public Date getEndSignTime_gte(){
		return getSqlMap().getWhere().getValue("sign_end_time", QueryType.GTE);
	}


	public String getIsHot() {
		return isHot;
	}

	public void setIsHot(String isHot) {
		this.isHot = isHot;
	}

	public List<KjActivityJob> getActivityJobList() {
		if(activityJobList == null){
			return ListUtils.newArrayList();
		}
		return activityJobList;
	}

	public void setActivityJobList(List<KjActivityJob> activityJobList) {
		this.activityJobList = activityJobList;
	}


	public int getIsort() {
		return isort;
	}

	public void setIsort(int isort) {
		this.isort = isort;
	}
}
